package com.app.qbake.module.square.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.wind.base.adapter.BaseRecyclerAdapter;
import com.wind.data.square.bean.Pic;
import com.app.qbake.R;

/**
 * Created by wind on 2018/9/6.
 */

public class PicAdapter  extends BaseRecyclerAdapter<Pic,PicAdapter.ViewHolder> {


    public PicAdapter(Activity activity, int layoutRes) {
        super(activity, layoutRes);
    }

    @Override
    public ViewHolder onCreateViewHolder(View v) {
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final Pic pic=getItem(position);
        Glide.with(mActivity)
                .load(pic.getUrl())
                .into(holder.iv);

        if (pic.isVideoCover()){
            holder.iv_video.setVisibility(View.VISIBLE);
        }else {
            holder.iv_video.setVisibility(View.GONE);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener!=null){
                    listener.onItemClick(pic,position);
                }
            }
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView iv;
        ImageView iv_video;
        public ViewHolder(View itemView) {
            super(itemView);
            iv=itemView.findViewById(R.id.iv);
            iv_video=itemView.findViewById(R.id.iv_video);
        }
    }
    private OnItemClickListener listener;
    public void setOnItemClickListener(OnItemClickListener listener){
        this.listener=listener;
    }
    public interface OnItemClickListener{
        void onItemClick(Pic pic,int position);
    }
}
